﻿@{
    ViewBag.Title = "Dormitory";
    Layout = "~/Views/Shared/_Admin.cshtml";
}
<div class="main-content" style="margin-left: 190px; min-height: 575px;">
    <div class="breadcrumbs" id="breadcrumbs">
        <ul class="breadcrumb">
            <li><i class="icon-home home-icon"></i><a href="/admin/index">Dashboard</a> </li>
            <li><a href="javascript:;">楼栋管理</a></li>
            <li class="active">楼栋维护</li>
        </ul>
        <!-- .breadcrumb -->
    </div>
    <div class="page-content">
        <p>
            <a href="/admin/adddormitory" class="btn btn-success">添加楼栋</a>
            @*<a href="/admin/addunit" class="btn btn-primary">添加销售单元</a>*@
        </p>
        <div class="row-fluid">
            <div class="span12">
                <h3 class="row-fluid header smaller lighter purple">
                    <span class="span12">已维护楼栋数据</span>
                    <!-- /span -->
                </h3>
                <div class="span11">
                @{
                    List<CollegeShop.Infrastructure.Entities.Entity.Dormitory> list = ViewBag.Dormitory;
                    if(list != null && list.Any())
                    {
                        @:<ol class="dd-list">
                        foreach(var item in list)
                        {
                            <li class="dd-item dd2-item">
                                <div class="dd-handle dd2-handle">
                                    <i class="normal-icon icon-building blue bigger-130"></i><i class="drag-icon icon-move bigger-125">
                                    </i>
                                </div>
                                <div class="dd2-content" style="margin-bottom:0px;">
                                    @item.DormitoryName
                                    @if(!String.IsNullOrEmpty(item.SalesUnitName))
                                    {
                                        @:&nbsp;&nbsp;&nbsp;(销售单元：@item.SalesUnitName)                                    
                                    } 
                                    <div class="pull-right action-buttons">
                                        <a class="blue" href="javascript:;" onclick="openforedit(this)" title="编辑"> 
                                            <i class="icon-pencil bigger-130"></i> 
                                        </a> 
                                        <a class="red" href="javascript:;" onclick="deleteDormitory('@item.ID',this)" title="删除"> 
                                            <i class="icon-trash bigger-130"></i> 
                                        </a> 
                                    </div>
                                </div>
                                <div class="widget-body" style="display:none;">
								    <div class="widget-main">
                                        <p>
										      <div class="row-fluid">
                                                <div class="span2" style="text-align:right; height:40px; line-height:40px;" >
                                                    楼栋名称：
                                                </div>
                                                <div class="span10">
                                                    <input type="text" dataitem="dormitory_@item.ID" value="@item.DormitoryName" class="input input-xlarge" />
                                                </div>
                                              </div>
                                        </p>
								    </div>
								    <div class="widget-toolbox padding-8 clearfix">
									    <button class="btn btn-xs btn-success pull-left" onclick="saveDormitory('@item.ID',this)">
										    <i class="icon-ok"></i><span class="bigger-110">保存更改</span>
									    </button> &nbsp;
								    </div>
							    </div>
                            </li>
                        }
                        @:</ol>
                    }
                }
                </div>
            </div>
        </div>
    </div>
</div>
@section tail{
    <script type="text/javascript">
        $(function () {
            $('#domitoryBlock').trigger('click');
        });
        function openforedit(sender) {
            $(sender).parent().parent().next('.widget-body').toggle();
        }
        function saveDormitory(id, sender) {
            var text = $('input[dataitem="dormitory_' + id + '\"]');
            $.ajax({
                url: '/admin/editDormitory',
                type: 'get',
                data: {
                    method: 'edit',
                    text: text.val(),
                    id: id
                },
                beforeSend: function () {
                    $(sender).after($('<i class="icon-spinner icon-spin icon-2x"></i>'));
                },
                success: function (res) {
                    $(sender).siblings('i').remove();
                    text.after($('<span class="badge badge-success">保存成功</span>'));
                }
            });
            window.setTimeout(function () {
                $('span.badge').fadeOut(800, null);
            },2000);
        }
        function deleteDormitory(id, sender) {
            if (confirm('确定删除此楼栋信息吗？')) {
                $.ajax({
                    url: '/admin/editDormitory',
                    type: 'get',
                    data: {
                        method: 'delete',
                        id: id
                    },
                    beforeSend: function () {
                        $(sender).parent().before($('<i class="icon-spinner icon-spin icon-2x"></i>'));
                    },
                    success: function (res) {
                        $(sender).parent().siblings('i').remove();
                        $(sender).parent().parent().parent().remove();
                    }
                });
            }
        }
    </script>
}